#include <bits/stdc++.h>

using namespace std;

struct Stack_Node{
    int val;
    struct Stack_Node* next;
    Stack_Node(int v):val(v),next(nullptr){};
};

class MinStack {
    Stack_Node* head;
    Stack_Node* ptr;
    Stack_Node* nim;
public:
    /** initialize your data structure here. */
    MinStack() {
        head=nullptr;
        nim=nullptr;
        ptr=nullptr;
    }
    
    void push(int x) {
        Stack_Node *n=new Stack_Node(x);
        if(!nim){
            nim=n;
        }else if(nim->val > x){
            nim=n;
        }
        if(!head){
            head=n;
            return ;
        }
        //这是个栈，故而将新节点放到最前面
        n->next=head;
        head=n;
    }
    
    void pop() {
        Stack_Node *p=head;
        if(nim==p){
            nim=head->next;
            ptr=nim;
            while(ptr){
               if(ptr->val<nim->val){
                   nim=ptr;
               } 
               ptr=ptr->next;
            }
        }
        head=head->next;
        delete p;
    }
    
    int top() {
        return head->val;
    }
    
    int min() {
        return nim->val;
    }
};

/**
 * Your MinStack object will be instantiated and called as such:
 * MinStack* obj = new MinStack();
 * obj->push(x);
 * obj->pop();
 * int param_3 = obj->top();
 * int param_4 = obj->min();
 */


class MinStack1 {
private:
    stack<int> s;
    stack<int> m;

public:
    
    void push(int x) {
        s.push(x);
        if(m.empty() || x <= m.top())
            m.push(x);
    }
    
    void pop() {
        if(s.top() == m.top())
            m.pop();
        s.pop();
        
    }
    
    int top() {
        return s.top();
    }
    
    int min() {
        return m.top();
    }
};


int main(){




    return 0;
}